# -*- coding: utf-8 -*-
#/usr/bin/env python
import math ,time

def retry(tries ,delay = 1 ,backoff = 2):
    if backoff <= 1:
        raise ValueError("backoff must be greater than 1")

    tries = math.floor(tries)
    if tries < 0:
        raise ValueError("tries must be 0 or greater")
    if delay <= 0:
        raise ValueError("delay must be greater than 0")
    def deco_retry(f):
        def f_retry(*args ,**kwargs):
            mtries ,mdelay = tries ,delay
            rv = f(*args ,**kwargs)
            while mtries > 0:
                if rv == True or type(rv) == str:
                    return rv
                mtries = -1
                time.sleep(mdelay)
                mdelay *= backoff

                rv = f(*args ,**kwargs)
            return False
        return f_retry
    return deco_retry